include ../../makedef.mk

INC := -I../../include/ -I../../include_api/ -I../../include_arch/ -I../../include_plat/

test_files := $(wildcard ./build/gtest*.o)
test_target := $(patsubst %.o,%.o,${test_files})

.PHONY:clean test all
all:$(target)
	@rm -f *.plist

CFLAGS := ${CFLAGS} -DFTEST

clean:
	rm ./build/*.o -f
	rm ./preproc/*.o.c -f
	rm ./assembly/*.S -f 
	rm ./assembly/*.ssa -f
	rm ./assembly/*.ll -f

run:$(test_target)

gtest%.o:cltest%.o
	@./$@ 
	@#> /dev/null
	@./$< 
	@#> /dev/null
	@#echo "----test $@, $< diff nothing is ok----"
	@#bash -c "diff <(./$@) <(./$<)"

%.o:%.c
	@mkdir -p build
	@mkdir -p preproc
	@mkdir -p assembly
	@echo "----generated pre-processed $@----"
	@${GCC} ${INC} ${PREDEFINED} ${CFLAGS} ${GCCFLAGS} $^ -E  > ./preproc/g$@.c
	@#${CLANG} ${INC} ${PREDEFINED} ${CFLAGS}  $^ -E  > ./preproc/cl$@.c
	@#${GCC} ${INC} ${PREDEFINED} ${COPT_FLAGS} ${CFLAGS} ${GCCFLAGS} $^ -fdump-tree-ssa -fverbose-asm -S -o ./assembly/g$@.S
	@#${CLANG} ${INC} ${PREDEFINED} ${COPT_FLAGS} ${CFLAGS} $^ -fverbose-asm -S -o ./assembly/cl$@.S
	@#${CLANG} ${INC} ${PREDEFINED} ${COPT_FLAGS} ${CFLAGS} $^ -emit-llvm -fverbose-asm -S -o ./assembly/cl$@.ll
	@echo "----run clang static analyzer----"
	@${CLANG} ${INC} ${PREDEFINED} --analyze $^
	@echo "----compiling using gcc with analyzer----"
	@${GCC} ${INC} ${PREDEFINED}  $^ ${LIBS} ${COPT_FLAGS} ${CFLAGS} ${GCCFLAGS} ${GCCANALYZER} -o ./build/g$@
	@echo "----compiling using clang----"
	@${CLANG} ${INC} ${PREDEFINED} $^ ${LIBS} ${COPT_FLAGS} ${CFLAGS} -o ./build/cl$@
